
package com.probiz.estore.content.dao.impl;

import java.util.List;

import com.probiz.estore.common.model.content.ContentRelatedType;
import com.probiz.estore.content.dao.ContentRelatedTypeDao;
import com.probiz.estore.content.model.ContentRelatedTypeSearchCriteria;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;

/**
 * Dao implementation for ContentRelatedType.
 */
public class ContentRelatedTypeDaoImpl extends	HibernateGenericDaoImpl<ContentRelatedType> implements ContentRelatedTypeDao {

	public ContentRelatedType getContentRelatedTypeByName(String typeName) {
		List list = getHibernateTemplate().find(
				"from ContentRelatedType vo where vo.typeName='" + typeName + "'");
		if (list.size() > 0) {
			return (ContentRelatedType) list.get(0);
		}
		return null;
	}

	public List<ContentRelatedType> getContentRelatedTypeBySearchCriteria(
			ContentRelatedTypeSearchCriteria contentRelatedTypeSearchCriteria) {
		StringBuffer sb = new StringBuffer(200);
    	sb.append("from ContentRelatedType where 1=1 ");
    	if(null != contentRelatedTypeSearchCriteria.getStatus()){
    		sb.append(" and status ="+contentRelatedTypeSearchCriteria.getStatus().shortValue());
    	}
    	if(null != contentRelatedTypeSearchCriteria.getIsApplyToCategory()){
    		sb.append(" and isApplyToCategory ="+contentRelatedTypeSearchCriteria.getIsApplyToCategory().shortValue());
    	}
    	if(null != contentRelatedTypeSearchCriteria.getIsApplyToContent()){
    		sb.append(" and isApplyToContent ="+contentRelatedTypeSearchCriteria.getIsApplyToContent().shortValue());
    	}
    	sb.append(" order by contentRelatedTypeId asc");
    	
    	return getHibernateTemplate().find(sb.toString());
	}

}
